package com.adee.design.structure.proxy.dynamicproxy.cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class Test1 {
    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(UserInterface.class);
        enhancer.setCallback(new MethodInterceptor() {
            @Override
            public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
                if("hello".equals(method.getName())) {
                    System.out.println("cglib代理接口，调用hello方法");
                }

                return null;
            }
        });
        UserInterface ui = (UserInterface)enhancer.create();
        ui.hello();
    }
}

interface UserInterface {
    void hello();
}


